<?php

namespace App\Http\Controllers;


use App\Services\Maze\MazeServices;

class MazeController extends BaseController
{
    public function maze()
    {
        $maze = MazeServices::getInstance()->readMaze("file/name.txt");
        $steps = MazeServices::getInstance()->walk($maze, [0, 0], [count($maze) - 1, count($maze[0]) - 1]);
//        echo '<pre>';
//        print_r($maze[5][4]);
//        echo '</pre>';
//        die();
//        $i = 0;
//        foreach ($steps as $row){
//            foreach($row as $val){
//                $i++;
//                echo $val;
//                if($i%5 == 0){
//                    echo "<br/>";
//                }
//
//            }
//
//        }
    }

    public function aaa()
    {
        $maze = [
            [0, 1, 0, 0, 0],
            [0, 0, 0, 1, 0],
            [0, 1, 0, 1, 0],
            [1, 1, 1, 0, 0],
            [0, 1, 0, 0, 1],
            [0, 1, 0, 0, 0]
        ];

        $start = [0, 0];
        $end = [count($maze) - 1, count($maze[0]) - 1];
        $queue[] = $start;
        $dirs = [
            [-1, 0],
            [0, -1],
            [1, 0],
            [0, 1]
        ];
        for ($i = 0; $i < count($queue); $i++) {
            $cur = $queue[$i];
            unset($queue[$i]);
            if($cur == $end){
                break;
            }
            foreach($dirs as $val){
                $next = [$val[0]+$cur[0],$val[1]+$cur[1]];
                if ($lu[0] < 0 || $lu[0] >= count($maze)) {
                    continue;
                }
                if ($lu[1] < 0 || $lu[1] >= count($grid[$lu[0]])) {
                    continue;
                }
            }

        }
    }
}
